const mysql = require('mysql2/promise')

const dbConfig = {
  host: 'localhost',
  user: 'root',
  password: 'GKL9512357',
  database: 'novel_platform',
  charset: 'utf8mb4'
}

async function checkSpecificUser () {
  let connection
  try {
    connection = await mysql.createConnection(dbConfig)

    const targetEmail = '1477042095@qq.com'

    console.log(`🔍 查找邮箱: ${targetEmail}`)

    // 查找特定用户
    const [users] = await connection.execute(
      'SELECT * FROM users WHERE email = ?',
      [targetEmail]
    )

    if (users.length > 0) {
      console.log('✅ 找到用户:')
      const user = users[0]
      console.log(`🆔 ID: ${user.id}`)
      console.log(`👤 用户名: ${user.username}`)
      console.log(`📧 邮箱: ${user.email}`)
      console.log(`📛 昵称: ${user.nickname}`)
      console.log(`🛡️ 角色: ${user.role}`)
      console.log(`📊 状态: ${user.status}`)
      console.log(`💰 金币: ${user.coins}`)
      console.log(`⭐ VIP: ${user.is_vip ? '是' : '否'}`)
      console.log(`📅 创建时间: ${user.created_at}`)
      console.log(`🔄 更新时间: ${user.updated_at}`)
    } else {
      console.log('❌ 未找到该用户')

      // 查看所有用户列表
      console.log('\n📋 数据库中所有用户:')
      const [allUsers] = await connection.execute(
        'SELECT id, username, email, nickname, role, status, created_at FROM users ORDER BY id'
      )

      if (allUsers.length > 0) {
        allUsers.forEach(user => {
          console.log(
            `${user.id}: ${user.username} (${user.email}) - ${user.nickname} [${user.role}] - ${user.status}`
          )
        })
      } else {
        console.log('数据库中没有任何用户')
      }
    }
  } catch (error) {
    console.error('❌ 错误:', error.message)
  } finally {
    if (connection) await connection.end()
  }
}

checkSpecificUser()
